﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Clients_admin_Banner : System.Web.UI.UserControl
{
    //<li><a href="http://hmweb.com.vn/vi/pro/64/61/cntt.aspx">Lập trình</a></li>
    private String children = "<li><a href='$Link'>$text</a></li>";
    private String parent = "<li><a>$text</a>$listChildren</li>";
    private String tagUlChildrent = "<ul class='children'>$listLi</ul>";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack) {
            LoadMenu();
        }
    }

    private void LoadMenu() {
        WebData db = new WebData();
        String strSql = "select code,item from tbl_list where isActive=1"
            + " group by code,item";
        DataTable parentTb = new DataTable();
        parentTb = db.tbl_Lists.GetDataTable(strSql, CommandType.Text);
        String url = "";
        foreach (DataRow row in parentTb.Rows) {
            String strCode = row["code"].ToString().Trim();
            String strText = row["item"].ToString().Trim();
            url = url + parent.Replace("$text", strText);
            DataTable childrenTb = null;
            strSql = "select VNI,Url,Path from tbl_list where code=@code and isActive=1";
            childrenTb = db.tbl_Lists.GetDataTable(strSql, CommandType.Text,
                new SqlParameter("@code", strCode));
            String sUrl = "";
            foreach (DataRow chilRow in childrenTb.Rows) {
                String sText = chilRow["VNI"].ToString().Trim();
                String UrlPath =Constant.ROOT_PATH + chilRow["Url"].ToString().Trim()+ chilRow["Path"].ToString().Trim();
                sUrl = sUrl + children.Replace("$text", sText).Replace("$Link", UrlPath);
            }
            if (!String.IsNullOrEmpty(sUrl)) {
                String s = tagUlChildrent.Replace("$listLi", sUrl);
                url = url.Replace("$listChildren", s);
            }
        }
        lblUrl.Text = url;
    }
}